﻿using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Cfg;

namespace Model
{
    public class ConnectionFactory
    {
        private Configuration _objConf = null;
        private static ISessionFactory _objFactory = null;

        public Configuration objConf
        {
            get { return _objConf; }
            set { _objConf = value; }
        }

        public static ISessionFactory objFactory
        {
            get { return ConnectionFactory._objFactory; }
            set { ConnectionFactory._objFactory = value; }
        }

        public ConnectionFactory()
        {
            try
            {
                this.objConf = new Configuration();
                this.objConf.AddClass(typeof(Model.Usuario));
                this.objConf.AddClass(typeof(Model.Cidade));
                this.objConf.AddClass(typeof(Model.Bairro));
                this.objConf.AddClass(typeof(Model.Uf));
                this.objConf.AddClass(typeof(Model.Endereco));
                this.objConf.AddClass(typeof(Model.Cliente));
                this.objConf.AddClass(typeof(Model.AdvogadoPrestador));
                this.objConf.AddClass(typeof(Model.Relato));
                this.objConf.AddClass(typeof(Model.Foro));
                this.objConf.AddClass(typeof(Model.Processo));

                objFactory = objConf.BuildSessionFactory();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static ISessionFactory getConnection()
        {
            if (objFactory == null)
            {
                ConnectionFactory objGlobal = new ConnectionFactory();
            }
            return objFactory;
        }


    }
}
